package com.linkme2night.view.openvenuesmap;
import com.linkme2night.R;
import com.linkme2night.controller.GoogleMapAPI;
import com.linkme2night.model.Venue;
import com.linkme2night.model.VenueDAO;
import com.linkme2night.view.CustomMenuActivity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
//import android.support.v4.app.FragmentActivity;
import android.text.InputType;
import android.view.View;
import android.widget.EditText;

public class OpenVenuesMapActivity extends CustomMenuActivity  {

	GoogleMapAPI map_api;
	Venue venues_data[];
	VenueDAO venue_dao;

	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_open_venues_map);
		map_api = new GoogleMapAPI(this);
		venue_dao = new VenueDAO();
		
		int venues_ids[] = venue_dao.getVenuesIDs();
		venues_data = new Venue[venues_ids.length];
		
		int vID;
		for(int i=0; i<venues_data.length; i++)
		{
			vID = venues_ids[i];
			venues_data[i] = new Venue(venue_dao.getName(vID), venue_dao.getOverallRanking(vID),
					venue_dao.getAddress(vID), venue_dao.getLatitude(vID), venue_dao.getLongitude(vID),
					venue_dao.getDescription(vID), vID);
			
			map_api.addMarker(venues_data[i]);
		}
	}

	public void onSetRadius (View v)
	{
		AlertDialog.Builder alert = new AlertDialog.Builder(this);

		alert.setTitle("Set Radius");
		alert.setMessage("Please set the radius, in meters, for which you want to see Venues arround you");

		// Set an EditText view to get user input 
		final EditText input = new EditText(this);
		input.setInputType(InputType.TYPE_CLASS_NUMBER);
		alert.setView(input);

		alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int whichButton) {
				String value = input.getText().toString();
				map_api.setRadius(Integer.parseInt(value));
			}
		});

		alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int whichButton) {
				// Canceled.
			}
		});

		alert.show();
	}
	
	public void onLocateMe(View v)
	{
		System.out.println("TESTE!! \n");
		map_api.locateMe();
	}
	
	/*@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.open_venues_map, menu);
		return true;
	}*/
}
